using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DAL;
using DTO;
using BUS;
using Utility;
public partial class Admin_Updatetinhtranggiaohang : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            LoadDropDownList();
            LoadData();
        }
    }
    private void LoadDropDownList()
    {
        tbTinhTrangGiaoHangCollection ttghCollection = tbTinhTrangGiaoHangBUS.GetAll();
        ddl_tentinhtranggiaohang.DataTextField = tbTinhTrangGiaoHangColumns.tenttgh.ToString();
        ddl_tentinhtranggiaohang.DataValueField = tbTinhTrangGiaoHangColumns.mattgh.ToString();
        ddl_tentinhtranggiaohang.DataSource = ttghCollection;
        ddl_tentinhtranggiaohang.DataBind();
    }
    private void LoadData()
    {
        try
        {
            int id = int.Parse(Request.QueryString["id"].ToString());
            txt_mahd.Text = id.ToString();

            tbHoaDon hd = tbHoaDonBUS.GetByID(id);
            ddl_tentinhtranggiaohang.SelectedValue = hd.tinhtranggiaohang.ToString();

        }
        catch
        {
            Response.Redirect("~/Admin/DanhSachDonHang.aspx");
        }
    }
    protected void btn_Update_Click(object sender, EventArgs e)
    {
        try
        {
            
            int id = int.Parse(Request.QueryString["id"].ToString());
            tbHoaDon hd = tbHoaDonBUS.GetByID(id);
            hd.mahd = id;
            hd.tinhtranggiaohang = int.Parse(ddl_tentinhtranggiaohang.SelectedValue);
            tbHoaDonBUS.UpdateTTGH(hd);
        }
        catch
        {
            
        }
        Response.Redirect("~/Admin/DanhSachDonHang.aspx");
        Response.Redirect(Request.RawUrl);

        

    }
}